package src.LLVM.cal;

import src.LLVM.IR;

public class GepIR implements IR {
    private final  String base;
    private String offset;

    private int len = -1;
    private final String result;

    public GepIR(String res, String base, String offset) {
        this.base = base;
        this.offset = offset;
        result = res;
    }


    public GepIR(String res, int y, String base) {
        this.len = y;
        this.base = base;
        result = res;
    }

    @Override
    public String toString() {
        if (len == -1) {//一维数组中一个
            return "\t" + result + " = getelementptr i32, i32* " +
                    base + ", i32 " + offset + "";
        } else {//抓二维数组中意为
            return "\t" + result + " = getelementptr [" + len + " x i32]," +
                    " [" + len +
                    " x i32]* " + base + ", i32 0, i32 0";
            //      " x i32]* " + "%v"+(this.regId-1)+", i32 0, i32 %v"+(this.regId-2)+"\n"
        }
    }
}